from time import sleep

from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from common.Utils import SearchDriver


class SearchFunc:
    driver = ""
    url = ""
    def __init__(self):
        self.driver = SearchDriver.driver
        self.url = "http://134.175.130.177:8080/"
        self.driver.get(self.url)

    def SearchSuccess(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div > div.search > input[type=text]").send_keys("for")
        sleep(2)
        self.driver.find_element(By.CSS_SELECTOR,"body > div > div.search > button").click()
        sleep(4)
        self.driver.find_element(By.CSS_SELECTOR,"body > div > div.result > div:nth-child(1) > a")
        sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "body > div > div.search > input[type=text]").clear()
        #self.driver.quit()

    def SearchFailed(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div > div.search > input[type=text]").send_keys("dwadasdwa")
        sleep(4)
        self.driver.find_element(By.CSS_SELECTOR,"body > div > div.search > button").click()
        sleep(2)
        actual = self.driver.find_element(By.CSS_SELECTOR, "body > div > div.result")
        assert actual.text == ""
        #self.driver.quit()



#FuncTest = SearchFunc()
#FuncTest.SearchSuccess()
#FuncTest.SearchFailed()